#    One Room And A Goblin Invasion
#    Copyright (C) 2014  Jannik Haberbosch
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.


class Timer( object ):
	"""A simple timer class that can be used as a timer to count up to a certain
	number.
	If that number is reached, the update() method returns "True" otherwise it
	returns "False".

	"""
	def __init__( self, limit, stepping, continuous_firing = True ):
		"""
		Parameters
			limit
			integer
			This is the upper limit for the timer.  If this number is reached,
			the update() method returns the boolean "True" instead of "False".

			stepping
			integer
			This defines the stepping.  A stepping of 2 means that the counter
			will be increased by 2 every time the update() method is called.

			continous_firing
			boolean
			A boolean that indicates, whether the timer should start from
			counting from the beginning again or whether it shouldn't after it
			has at least once fired an event.
			The default is set to 'True'.

		"""
		self.limit = limit
		self.stepping = stepping
		self.continuous_firing = continuous_firing
		self.count = 0


	def update( self ):
		"""Returns 'True' if the timer has reached the limit, otherwise 'False'
		is returned.

		"""
		self.count += self.stepping
		
		if self.count >= self.limit:
			self.count = 0
			return True
				
		else:
			return False
